//
//  ViewController.m
//  UI_01homework
//
//  Created by dllo on 16/6/3.
//  Copyright © 2016年 dllo. All rights reserved.
//

#import "ViewController.h"
#import "CustomViews.h"
#import "UIColor+RandomColor.h"


@interface ViewController ()

@property(nonatomic, retain)CustomViews *rainView;

@end







@implementation ViewController



#pragma mark -1. UIViewController 生命周期
// 重写UIViewController的初始化方法
-(instancetype)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
    self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
    if (self) {
        NSLog(@"%d, %s", __LINE__, __FUNCTION__);
    }
    return self;
}
-(instancetype)init{
    self = [super init];
    if (self) {
        NSLog(@"%d, %s", __LINE__, __FUNCTION__);
    }
    return self;
}
/**********************************************************************************/

/**1. 加载视图***********************************/
-(void)loadView{
    [super loadView];
}
/*****************************************************************************/


/**2. 视图加载完成***-------->在这里加载子视图*******/
- (void)viewDidLoad {
    [super viewDidLoad];
     self.view.backgroundColor = [UIColor whiteColor];
    self.view.alpha = 0.3;
    /*----------->创建子视图的方法***/
    [self creatSubViews];
//    [self addCostomViews];
    [self creatButton];
    
}
/*****************************************************************************/



/**3.视图将要显示*******************************/
-(void)viewWillAppear:(BOOL)animated{
    [super viewWillAppear:animated];
}
/******************************************************************************/




/**4.视图显示完成*******************************/
-(void)viewDidAppear:(BOOL)animated{
    [super viewDidAppear:animated];
}
/******************************************************************************/



      /**************----------->创建子视图的方法*****************/
-(void)creatSubViews{
//    UIView *blueViews = [[UIView alloc]initWithFrame:CGRectMake(10, 50, 30, 214)];
//    blueViews.backgroundColor = [UIColor yellowColor];
//    [self.view addSubview:blueViews];
//    [blueViews release];
//    
//    /*******UIViews常用的API*****/
//    blueViews.alpha = 0.5;
//    NSLog(@"%@", blueViews.subviews);
//    NSLog(@"%@", blueViews.superview);
//    blueViews.center = CGPointMake(45, 32);
//    blueViews.tag = 100; // 可以通过视图的标记找到blueViews这个视图
//    UIView *find = [self.view viewWithTag:100];  // 这样find就是blueViews了
//    NSLog(@"%@,%@", blueViews, find);
//    
    // 红色
    UIView *view1 = [[UIView alloc]initWithFrame:CGRectMake(50, 50, 50, 50)];
    view1.backgroundColor = [UIColor redColor];
    [self.view addSubview:view1];
    [view1 release];
    
    // 黄色
    UIView *view2 = [[UIView alloc]initWithFrame:CGRectMake(100, 50, 50, 50)];
    view2.backgroundColor = [UIColor yellowColor];
    [self.view addSubview:view2];
    [view2 release];
    
    // 绿色
    UIView *view3 = [[UIView alloc]initWithFrame:CGRectMake(150, 50, 50, 50)];
    view3.backgroundColor = [UIColor greenColor];
    [self.view addSubview:view3];
    [view3 release];
    
    // 蓝色
    UIView *view4 = [[UIView alloc]initWithFrame:CGRectMake(200, 50, 50, 50)];
    view4.backgroundColor = [UIColor blueColor];
    [self.view addSubview:view4];
    [view4 release];
    
    // 灰色
    UIView *view5 = [[UIView alloc]initWithFrame:CGRectMake(250, 50, 50, 50)];
    view5.backgroundColor = [UIColor orangeColor];
    [self.view addSubview:view5];
    [view5 release];
    
    
    // *********************************************************************************//
    UIView *cyan1 = [[UIView alloc]initWithFrame:CGRectMake(50, 120, 60, 40)];
    cyan1.backgroundColor = [UIColor cyanColor];
    [self.view addSubview:cyan1];
    [cyan1 release];
    
    UIView *cyan2 = [[UIView alloc]initWithFrame:CGRectMake(50, 190, 60, 40)];
    cyan2.backgroundColor = [UIColor cyanColor];
    [self.view addSubview:cyan2];
    [cyan2 release];

    
    UIView *cyan3 = [[UIView alloc]initWithFrame:CGRectMake(190, 120, 130, 40)];
    cyan3.backgroundColor = [UIColor cyanColor];
    [self.view addSubview:cyan3];
    [cyan3 release];
    
    
    UIView *cyan4 = [[UIView alloc]initWithFrame:CGRectMake(190, 190, 130, 40)];
    cyan4.backgroundColor = [UIColor cyanColor];
    [self.view addSubview:cyan4];
    [cyan4 release];
    
    
    UIView *cyan5 = [[UIView alloc]initWithFrame:CGRectMake(70, 270, 70, 50)];
    cyan5.backgroundColor = [UIColor cyanColor];
    [self.view addSubview:cyan5];
    [cyan5 release];
    
    
    UIView *cyan6 = [[UIView alloc]initWithFrame:CGRectMake(210, 270, 70, 50)];
    cyan6.backgroundColor = [UIColor cyanColor];
    [self.view addSubview:cyan6];
    [cyan6 release];
    
    

}


/*************添加自定义的视图**************/
-(void)addCostomViews{
    CustomViews *customView = [[CustomViews alloc]initWithFrame:CGRectMake(21, 32, 54, 65) withColor:[UIColor greenColor]];
    
    [self.view addSubview:customView];
    [customView release];
    self.rainView = [[CustomViews alloc]initWithFrame:CGRectMake(78, 321, 55, 66)];
    [self.view addSubview:_rainView];
    [_rainView release];


}



-(void)creatButton{
    UIButton *button = [UIButton buttonWithType:UIButtonTypeSystem];
    button.backgroundColor = [UIColor blackColor];
    
    button.frame = CGRectMake(110, 500, 120, 90);
    
    [self.view addSubview:button];
    
    [button setTitle:@"点我现第三题" forState:UIControlStateNormal];
    [button addTarget:self action:@selector(creatAnewView:) forControlEvents:UIControlEventTouchUpInside];
    
}

// 通过按钮创建一个新的界面 界面颜色是5 X 8 的色块
-(void)creatAnewView:(UIButton *)parameterbutton{
    
    self.view.backgroundColor = [UIColor yellowColor];
    CGFloat w = self.view.frame.size.width;
    CGFloat h = self.view.frame.size.height;
    
    for (NSInteger i = 0; i < 9; i ++) {
        for (NSInteger j = 0; j < 5; j ++) {
            UIView *newView = [[UIView alloc]initWithFrame:CGRectMake(w / 5 * j, h / 8 * i, w, h)];
            newView.backgroundColor = [UIColor randomColor];
            [self.view addSubview:newView];
            [newView release];
        }
    }
    
}
























- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

@end
